package com.gabry.dep;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;

import static org.objectweb.asm.Opcodes.INVOKESTATIC;

/**
 * Created by ShaoJie.Wu on 2017/1/12 8:57.
 * 功能：
 * <p>
 * 备注：
 */
public class DepMethodAdapter extends MethodAdapter {
    private String fileName = "";
    private String className = "";
    private String methodName = "";
    /**
     * 方法ID
     */
    private int mMethodId = 0;
    public void visitLineNumber(int var1, Label var2) {
        System.out.println("className="+className+",methodName="+methodName+",var="+var1+" ,label.offset="+var2.getOffset()+",label.info="+var2.info);
        super.visitLineNumber(var1, var2);
    }

    /**
     * @param visitor
     * @param fileName
     * @param className
     * @param methodName
     */
    public DepMethodAdapter(MethodVisitor visitor, String fileName, String className, String methodName) {
        super(visitor);
        this.fileName = fileName;
        this.className = className;
        this.methodName = methodName;
    }

    /* (non-Javadoc)
     * @see org.objectweb.asm.MethodAdapter#visitCode()
     */
    public void visitCode() {
        // 传参数
        this.visitLdcInsn(mMethodId);
        this.visitMethodInsn(INVOKESTATIC, "com/gabry/utils/Profiler", "PrintDeps", "(I)V");
        super.visitCode();
    }
}
